package com.bootdo.analyze.service.impl;

import com.bootdo.analyze.dao.ClientSellAIDao;
import com.bootdo.analyze.dao.GoodsSellAIDao;
import com.bootdo.analyze.domain.ClientSellAIDO;
import com.bootdo.analyze.domain.GoodsSellAIDO;
import com.bootdo.analyze.service.ClientSellAIService;
import com.bootdo.analyze.service.GoodsSellAIService;
import com.bootdo.analyze.util.Dto;
import com.bootdo.analyze.util.DtoUtil;
import com.bootdo.analyze.util.WeiDuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ClientSellAIServiceImpl implements ClientSellAIService {
    @Autowired
    private ClientSellAIDao clientSellAIDao;



    @Override
    public int count(Map<String, Object> map) {
        return clientSellAIDao.count(map);
    }

    @Override
    public List<ClientSellAIDO> getClientFluctuate(Map<String,Object> map) {
        List<ClientSellAIDO> clientSellAIDOList = clientSellAIDao.getClientFluctuate(map);
        for (ClientSellAIDO clientSellAIDO:clientSellAIDOList){
            int id = clientSellAIDO.getId();
            String str_salescount=clientSellAIDao.getSalescount(id);
            if (str_salescount==null || str_salescount==""){
                str_salescount="0";
            }
            clientSellAIDO.setSalescount(Integer.parseInt(str_salescount));
            String str_totalPrices=clientSellAIDao.getTotalPrices(id);
            if (str_totalPrices==null || str_totalPrices==""){
                str_totalPrices="0";
            }
            clientSellAIDO.setTotalPrices(Double.parseDouble(str_totalPrices));

           List<WeiDuUtil> weiDuUtilList= clientSellAIDO.getWeiDuUtilList();

            List<WeiDuUtil> weiDuUtils = new ArrayList<WeiDuUtil>();

            Integer bdint = 0;
            for (WeiDuUtil weiDuUtil:weiDuUtilList){
                System.out.println("weiDuUtil-----------------"+weiDuUtil.getCountWD());
                String b = weiDuUtil.getBusinessDay();
                String bd = b.substring(b.length()-2);
                 bdint = Integer.parseInt(bd);
                weiDuUtil.setBusinessDay(bdint.toString());
                System.out.println(weiDuUtil.getBusinessDay()+"---------------------------day");
                for (int i =1 ; i<=31 ;i++){
                    WeiDuUtil weiDuUtil1 = new WeiDuUtil();
                    weiDuUtil1.setCountWD(0);
                    weiDuUtil1.setPricesWD(0.00);
                    weiDuUtil1.setBusinessDay(Integer.toString(i));
                    if (i==bdint){
                        weiDuUtils.add(weiDuUtil);
                        System.out.println(weiDuUtils.get(i-1).getCountWD());
                    }else {
                        weiDuUtils.add(weiDuUtil1);
                    }

                }
            }
           /* WeiDuUtil weiDuUtil1 = new WeiDuUtil();
            for (int i =1 ; i<=31 ;i++){
                weiDuUtil1.setCountWD(0);
                weiDuUtil1.setPricesWD(0.00);
                weiDuUtil1.setBusinessDay(i+"");
                weiDuUtils.add(weiDuUtil1);

                System.out.println(weiDuUtil1.getBusinessDay()+"---------------------------day1222");


                System.out.println(i+"-----------------------------"+weiDuUtils.get(i-1).getCountWD());

            }
            for (WeiDuUtil weiDuUtil:weiDuUtilList){
                System.out.println(weiDuUtil.getBusinessDay()+"---------------------------day11111");
                String b = weiDuUtil.getBusinessDay();
                String bd = "-1";
                if (b.length()>2){
                    bd = b.substring(b.length()-2);
                    bdint = Integer.parseInt(bd);
                    weiDuUtil.setBusinessDay(bdint.toString());
                }
                if (weiDuUtil.getBusinessDay().equals(i+"")){
                    weiDuUtils.add(weiDuUtil);
                }
                else {

                }
            }*/



            clientSellAIDO.setWeiDuUtilList(weiDuUtils);


        }
        return clientSellAIDOList;


    }

    @Override
    public List<WeiDuUtil> getClientInfo(Map<String, Object> map) {
        List<WeiDuUtil> weiDuUtilList = clientSellAIDao.getClientInfo(map);
        List<WeiDuUtil> weiDuUtils = new ArrayList<WeiDuUtil>();

        Integer bdint = 0;
        for (WeiDuUtil weiDuUtil:weiDuUtilList){
            System.out.println("weiDuUtil-----------------"+weiDuUtil.getCountWD());
            String b = weiDuUtil.getBusinessDay();
            String bd = b.substring(b.length()-2);
            bdint = Integer.parseInt(bd);
            weiDuUtil.setBusinessDay(bdint.toString());
            System.out.println(weiDuUtil.getBusinessDay()+"---------------------------day");
            for (int i =1 ; i<=12 ;i++){
                WeiDuUtil weiDuUtil1 = new WeiDuUtil();
                weiDuUtil1.setCountWD(0);
                weiDuUtil1.setPricesWD(0.00);
                weiDuUtil1.setBusinessDay(Integer.toString(i));
                if (i==bdint){
                    weiDuUtils.add(weiDuUtil);
                    System.out.println(weiDuUtils.get(i-1).getCountWD());
                }else {
                    weiDuUtils.add(weiDuUtil1);
                }

            }
        }
        return weiDuUtils;
    }

    @Override
    public List<ClientSellAIDO> getClientSell(Map<String, Object> map) {

        return clientSellAIDao.getClientSell(map);
    }


}
